<template>
  <!-- 调用该组件的地方有canvas等原生组件，故 使用cover这种组件 -->
  <view v-if="show" class="gift-modal-container" @touchmove.stop.prevent>
   <view class="main-container">
      <view class="main-wrapper">
        <!-- <cover-view style="position: fixed;left: 0;right: 0;top: -9999px;bottom: -9999px;z-index:1;background-color: rgba(0,0,0,.6);" mode="widthFix" :src="staticImgs.maskBg"></cover-view> -->
        <!-- 默认定位，当背景 -->
        <cover-image style="position: fixed;left: 0;right: 0;top: 0;bottom: 0;z-index: 999;" mode="widthFix" :src="staticImgs.maskBg"></cover-image>
        <!-- 默认定位，当背景 -->
        <cover-image class="flash-img rotating" mode="widthFix" :src="staticImgs.flash"></cover-image>
        <!-- 绝对定位，层级前置 -->
        <cover-view class="intro-text-wrapper" @click="confirmHandle">
          <cover-view class="coupon-box-wrapper " v-for="(item,index) in couponList" :key="index">
            <!-- 优惠券背景，默认定位 -->
            <cover-image class="coupon-bg-img" mode="widthFix" :src="staticImgs.couponBg"></cover-image>
            
            <!-- 优惠券用绝对定位，层级前置 -->
            <cover-view class="coupon-box"> 
              <cover-view class="left-con">
                <cover-view class="num">{{item.num}}</cover-view>
                <cover-view class="text">{{item.unit}}</cover-view>
              </cover-view>
              <cover-view class="ads-line"></cover-view>
              <cover-view class="right-con">
                <cover-view class="row-1">{{item.name}}</cover-view>
                <cover-view class="row-2">有效期至：{{item.endTime}}</cover-view>
              </cover-view>
            </cover-view>
            
          </cover-view>
        </cover-view>
        <cover-image class="main-img" mode="widthFix" :src="staticImgs.bg"></cover-image>
        <cover-image @click="confirmHandle" mode="widthFix" class="btn-img" :src="staticImgs.btn"></cover-image>
        
        
      </view>
   </view> 
  </view>
</template>

<script>
  export default {
    name: "GiftModal",
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      eshopDiscountList:{
        type:String,
        default:''
      }
    },
    watch: {
      visible(val) {
        console.log('-----visible-----',val)
        this.show = val
      },
      eshopDiscountList:{
        immediate:true,
        handler(val){
          if(val){
            const tmpArr = JSON.parse(val)
            
            tmpArr.forEach(item=>{
              this.couponList.push({
                name:item.discountName,
                num:item.discountType === 4 ? item.immediately : item.discount,
                unit:item.discountType === 4 ? '元' : '折',
                endTime:this.$dayjs(item.discountEndTime).format('YYYY.MM.DD HH:mm')
              })  
            })            
          }
        }
      },
    },
    data() {
      return {
        staticImgs:{
          maskBg:this.imgBaseURL + '/scl/gift-modal/gift-modal-bg.png',
          bg: this.imgBaseURL + '/scl/gift-modal/modal-bg-yiyuan.png',
          couponBg: this.imgBaseURL + '/scl/gift-modal/yiyuan-coupon-bg.png',
          btn: this.imgBaseURL + '/scl/gift-modal/yiyuan-modal-btn.png',
          flash: this.imgBaseURL + '/scl/gift-modal/gift-flash.png',
          main: this.imgBaseURL + '/scl/gift-modal/gift-main.png',
        },
        show: false,
        couponList:[]
      }
    },
    methods: {
      confirmHandle(){
        this.$emit('confirm')
      },
      touchEvent(e){
        console.log(e,'----touchEvent----')
      }
    }
  }
</script>

<style lang="scss" scoped>
  
  /* 定义旋转动画效果 */
  @keyframes rotate {
   0% {
      transform: rotate(0);
  }

  25% {
      transform: rotate(90deg);
  }

  50% {
      transform: rotate(180deg);
  }

  75% {
      transform: rotate(270deg);
  }

  100% {
      transform: rotate(360deg);
  }

  }

  
  
  .rotating{
    animation: rotate 5s linear infinite;
    -webkit-animation: rotate 5s linear infinite;
  }
  
  
  /* 定义旋转动画效果 */
  @keyframes point {
  	0% {
  	    transform: translateZ(0);
  	}
  	// 5% {
  	//     transform: translate3d(5px,5px,0);
  	// }
  	15% {
  	    transform: translate3d(-5px,-5px,0);
  	}
  	25% {
  	    // transform: translate3d(5px,5px,0);
        transform: translate3d(0,0,0);
  	}
  	45% {
  	    transform: translate3d(-5px,-5px,0);
  	}
  	55% {
  	    // transform: translate3d(5px,-5px,0);
        transform: translate3d(0,0,0);
  	}
  	65% {
  	    transform: translate3d(-5px,-5px,0);
  	}
  	80% {
  	    // transform: translate3d(5px,5px,0);
        
  	}
  	100% {
  	    transform: translate3d(0,0,0);
  	}
  
}
  
  .pointing{
    animation: point 3s linear infinite;
    -webkit-animation: point 3s linear infinite;
  }
  
  
  
  .gift-modal-container{
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999;
    box-sizing: border-box;
    background-size: 100% 100%; 
    padding-top: 18vh;
    // background-color: red;
    
    .main-wrapper{
      height: 904rpx;
      width: 744rpx;
      margin: auto;
      position: relative;
      
      .flash-img{
        position: absolute;
        z-index: 999;
        top: 0;
        left: 46rpx;
        right: 0;
        width: 624rpx;
        height: 624rpx;
        margin-top: 82rpx;
      }
      
      .intro-text-wrapper{
        position: absolute;
        z-index: 1000;
        top: 404rpx;
        left: 0;
        right: 0;
        
        bottom:  194rpx;
        
        display: flex;
        justify-content: flex-end;
        align-items: center;
        flex-direction: column;
        row-gap: 24rpx;
        
        .coupon-box-wrapper{
          position: relative;
          width: 424rpx;
          height: 130rpx;
          margin-top: 24rpx;
          
          .coupon-bg-img{
            width: 424rpx;
            height: 130rpx;
          }
          
          .coupon-box{
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            z-index: 1000;
            display: flex;
            align-items: center;
            // background-color: red;
            
            .left-con{
              width: 128rpx;
              height: 100%;
              display: flex;
              // justify-content: center;
              align-items: center;
              box-sizing: border-box;
              padding-left: 36rpx;
              // background-color: #333;
              
              .num{
                font-family: PingFang-SC, PingFang-SC;
                font-weight: bold;
                font-size: 70rpx;
                color: #8D310E;
                line-height: 98rpx;
                text-align: left;
                font-style: normal;
              }
              .text{
                font-family: PingFang-SC, PingFang-SC;
                font-weight: bold;
                font-size: 28rpx;
                color: #8D310E;
                line-height: 40rpx;
                text-align: left;
                font-style: normal;
                margin-top: 28rpx;
                margin-left: 6rpx;
              }
            }
            
            .ads-line{
              // width: 2rpx;
              height: 88rpx;
              border-left: 1px dashed #DCB6A9;
            }
            
            .right-con{
              width: 294rpx;
              height: 100%;
              
              display: flex;
              flex-direction: column;
              justify-content: center;
              // align-items: center;
                  padding-left: 24rpx;
                  box-sizing: border-box;
              
              // background-color: #C3784A;
              
              
              .row-1{
                font-family: PingFang-SC, PingFang-SC;
                font-weight: bold;
                font-size: 30rpx;
                color: #8D310E;
                line-height: 42rpx;
                text-align: left;
                font-style: normal;
                margin-bottom: 8rpx;
              }
              .row-2{
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                font-size: 18rpx;
                color: #999999;
                line-height: 25rpx;
                text-align: left;
                font-style: normal;
              }
            }
          }
          
        }
        
        .text-1{
          width: 400rpx;
          font-family: PingFang-SC, PingFang-SC;
          font-weight: bold;
          font-size: 50rpx;
          color: #F8431D;
          line-height: 70rpx;
          text-align: center;
          font-style: normal;
        }
        .text-2{
          margin-top: 16rpx;
          margin-bottom: 214rpx;
          
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 26rpx;
          color: #C3784A;
          line-height: 37rpx;
          text-align: center;
          font-style: normal;
          
          width: 230rpx;
          height: 56rpx;
          border-radius: 28rpx;
          border: 1rpx solid #C3784A;
          
          line-height: 56rpx;
        }
      }

  

      .main-img{
        position: absolute;
        z-index: 999;
        height: 904rpx;
        width: 744rpx;
        top: 0;
        left: 0;
        
        bottom:  0;
      }
      
      .btn-img{
        width: 280rpx;
        height: 80rpx;
        position: absolute;
        z-index: 999;

        bottom: 74rpx;
        left: 50%;
        transform: translateX(-50%);
      }
    }
    .btns-wrapper{
      position: relative;
      margin:  auto;
      margin-top: 42rpx;
      display: flex;
      justify-content: center;
      width: 290rpx;
      // width: 100%;
      height: 150rpx;
      overflow: initial;

      

      
      .btn-img{
        width: 290rpx;
        height: 100rpx;
        position: absolute;
        z-index: 999;
        left: 0;
        top: 0;
      }
      .hand-img-abs{
        width: 130rpx;
        height: 114rpx;
        position: absolute;
        z-index: 999;
        right: -84rpx;
        top: 38rpx;
      }
    }
  }
</style>